%STRUCT_STR2DOUBLE Convert all text strings in a structure into doubles.
%   STRUCTURE = STRUCT_STR2DOUBLE(STRUCTURE)
%   The functions recursively goes through the STRUCTURE and converts all
%   elements which are convertible by str2double into double values.
%   Inconvertible elements remain unchanged.
%
%   See also parseXML.


function structure = struct_str2double(structure)
    if ischar(structure)
        tmp = str2double(structure);
        if ~isnan(tmp)
            structure = tmp;
        end%if
    elseif isstruct(structure)
        fn = fieldnames(structure);
        for i = 1:length(fn)
            if ischar (structure.(fn{i}) )
                %fprintf('ischar!\n');
                tmp = str2double( structure.(fn{i}) );
                if ~isnan(tmp)
                     structure.(fn{i}) = tmp;
                end%if
            elseif isstruct( structure.(fn{i}) )
                %fprintf('isstruct!\n');
                if length(structure.(fn{i}) ) == 1
                     structure.(fn{i}) = struct_str2double( structure.(fn{i}) );
                end%if    
            elseif iscell( structure.(fn{i}) )
                %fprintf('iscell!\n');
                for j = 1:length(structure.(fn{i}) )
                    structure.(fn{i}){j} = struct_str2double( structure.(fn{i}){j} );
                end%for
            end%if
        end%for
    end%if
end%function